package com.mz.util;

import java.util.HashMap;
import java.util.Map;

public class PageUtil {
	public static Map<String, Object> map = new HashMap<String, Object>();
	private Integer pageIndex;
	private Integer pageSize = 5;
	private String key = "";

	/**
	 * @return the pageIndex
	 */
	public Integer getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex
	 *            the pageIndex to set
	 */
	public void setPageIndex(Integer pageIndex) {
		if (pageIndex == null || pageIndex < 1 ) {
			pageIndex = 1;
		}
		this.pageIndex = (pageIndex - 1) * pageSize;
	}

	/**
	 * @return the pageSize
	 */
	public Integer getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize
	 *            the pageSize to set
	 */
	public void setPageSize(Integer pageSize) {
		if (pageSize == null || pageSize < 0 || pageSize > 100) {
			pageSize = 5;
		}
		this.pageSize = pageSize;
	}

	/**
	 * @return the key
	 */
	public String getKey() {
		if (key == null || key.trim().equals("")) {
			this.key = "";
		}
		return key;
	}

	/**
	 * @param key
	 *            the key to set
	 */
	public void setKey(String key) {
		if (key == null || key.trim().equals("")) {
			key = "%%";
		}
		this.key = key;
	}

	public PageUtil(Integer pageIndex, Integer pageSize, String key) {
		super();
		if (pageSize == null || pageSize < 0) {
			pageSize = 5;
		}

		this.pageSize = pageSize;
		if (pageIndex == null || pageIndex < 1 ) {
			pageIndex = 1;
		}

		this.pageIndex = (pageIndex - 1) * pageSize;

		if (key == null || key.trim().equals("")) {
			key = "";
		}
		this.key = "%" + key + "%";

	}

	public PageUtil() {
		super();
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "PageUtil [pageIndex=" + pageIndex + ", pageSize=" + pageSize + ", key=" + key + "]";
	}

}
